//
//  rightDrawerViewController.m
//  myselfTest
//
//  Created by Lucifer on 15-5-19.
//  Copyright (c) 2015年 xuxzhou. All rights reserved.
//

#import "rightDrawerViewController.h"
#import "myOrderViewController.h"
#import "AppDelegate.h"
#import "UIImageView+WebCache.h"
@interface rightDrawerViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UIImageView * headerImageView;
@property(nonatomic,strong)UITableView * tabView;
@property(nonatomic,strong)NSMutableArray * dataArray;
@end

@implementation rightDrawerViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initialiseDataContainer];
    [self buildUI];
}
#pragma mark - UI
-(void)buildUI{
    [self buildHeaderImage];
    [self buildTabView];

}
-(void)buildHeaderImage{
    _headerImageView=[[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5, 50, 100, 100)];
    _headerImageView.userInteractionEnabled=YES;
    UITapGestureRecognizer * tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headerImageViewClicked:)];
    [_headerImageView addGestureRecognizer:tapGesture];
    _headerImageView.layer.cornerRadius=_headerImageView.frame.size.width/2;
    _headerImageView.backgroundColor=[UIColor redColor];
    _headerImageView.layer.borderWidth=5;
    [_headerImageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.caos.bg.it/immagini/albero_3.jpg"] placeholderImage:[UIImage imageNamed:@"gbp"]];
    _headerImageView.layer.borderColor=[[UIColor brownColor]CGColor];
    _headerImageView.layer.masksToBounds=YES;
    [self.view addSubview:_headerImageView];
}
-(void)headerImageViewClicked:(UITapGestureRecognizer *)tapGestureRecognizer{
    NSLog(@"点击头像");


}
-(void)buildTabView{
    _tabView=[[UITableView alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.3, _headerImageView.frame.size.height+_headerImageView.frame.origin.y, self.view.frame.size.width*0.7, self.view.frame.size.height-_headerImageView.frame.size.height-_headerImageView.frame.origin.y)];
    _tabView.delegate=self;
    _tabView.dataSource=self;
    _tabView.tableFooterView=[[UIView alloc]init];
    [self.view addSubview:_tabView];


}
#pragma mark - TabViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section==0) {
        return 80;
    }
    return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView * view =[[UIView alloc]initWithFrame:CGRectMake(0, 2, _tabView.frame.size.width, 98)];
    view.backgroundColor=[UIColor whiteColor];
    return view;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return _dataArray.count/2;
    }
    return _dataArray.count/2+_dataArray.count%2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * myselfCellName =@"myselfCellName";
    UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:myselfCellName];
    if (cell==nil) {
        cell=[[UITableViewCell alloc ]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:myselfCellName];
    }
    if (indexPath.section==0) {
        cell.textLabel.text=_dataArray[indexPath.row];
    }else{
    cell.textLabel.text=_dataArray[indexPath.row+_dataArray.count/2];
    
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.detailTextLabel.text=[NSString stringWithFormat:@"%ld",indexPath.section];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    myOrderViewController * myOrder =[[myOrderViewController alloc]init];
    myOrder.hidesBottomBarWhenPushed=YES;
    [[[AppDelegate shareApplication] sideMenu]hideMenuViewController];
    [[[AppDelegate shareApplication] onePageNav] pushViewController:myOrder animated:YES];
}
#pragma mark -Data
-(void)initialiseDataContainer{
    _dataArray=[NSMutableArray arrayWithObjects:@"我的订单",@"我的收藏",@"购物车",@"相册",@"我的小说",@"我的音乐",@"我的视频",@"设置", nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
